// JavaScript Document

function showAddProductDlg(obj)
{
	add_product_window.show(obj)
}

function showAddVendorDlg()
{
	add_vendor_window.show();
}
function deleteSoftware()
{
	alert("delte  ----  "+grid_list.getSelectionModel().getSelections()[0].json);
}

function onFilterTypeSelected(id,name)
{
	alert("Filter Type: " + id + " -- " + name);
}

function onFilterProductSelected(id,name)
{
	alert("Filter Product Type: " + id + " -- " + name);
}

function changeSoftware()
{
	alert("delte  ----  "+grid_list.getSelectionModel().getSelections()[0].json[6]);
}
///////////////////////////////


var add_software_Form;


var add_assets_post_url = "test.jsp";

///////Generate Assets List here
var workstationData = [
	["Workstation1","aa","window xp professional","tag1","In Store","dexter","web"],
	["Workstation1","bb","window vista","tag1","In Store","twj","web"]
];

////// 
var SelectSoftType = 
[
	["1","Excluded"],
	["2","Freeware"],
	["3","Managed"],
	["4","Prohibited"],
	["5","Shareware"],
	["6","UnIdentified"]
]
/////// Generate Software Category Here
var SoftwareCategoryList =
[
 	["0","Database"],
	["1","Development"],
	["2","Operation System"],
	["3","Game"],
	["4","Graphics"],
	["5","Internet"],
	["6","Multimedia"],
	["7","Accounting"],
	["8","Others"]
]
//////Generate Filter Type Here
var FilterType = 
[
 	["0","All"],
	["1","Excluded"],
	["2","Freeware"],
	["3","Managed"],
	["4","Prohibited"],
	["5","Shareware"],
	["6","UnIdentified"]
]




/////////////////////////////////////////////
function createNewSoftware()
{
	add_new_window.show(this.getEl());
}
//////////////////////////
// Filter Type Store
var filter_type_store = new Ext.data.SimpleStore
({
	fields:["returnValue","textValue"]
})
filter_type_store.loadData(FilterType);
///////////////////////////
///Software type store

var software_type_store = new Ext.data.SimpleStore
({
	fields:["returnValue","textValue"]
})
software_type_store.loadData(SelectSoftType);
///////////////////////////
// Software category store
var software_category_store = new Ext.data.SimpleStore
({
	fields:["returnValue","textValue"]
})
software_category_store.loadData(SoftwareCategoryList);

//////////////////////////////
//Assets List Store







var store = new Ext.data.SimpleStore({
	fields: [
	   {name: 'st_Workstation'},
	   {name: 'st_Model'},
	   {name: 'st_OS'},
	   {name: 'st_Service_Tag'},
	   {name: 'st_Asset_State'},
	   {name: 'st_User'},
	   {name: 'st_Department'}
	]
});
store.loadData(workstationData);

function toggleDetails(btn, pressed){

}



///////////Filter Combobox
var filter_type_combo = new Ext.form.ComboBox
({
	xtype:'combo',
	store:filter_type_store,
	valueField:'returnValue',
	displayField:'textValue',
	mode:'local',
	forceSelection:true,
	blankText:'Please select a type.',
	editable:false,
	triggerAction:'all',
	
	name: 'form_filter_type',
	width:140,
	anchor:'100%'
})
filter_type_combo.on("select",function(a,b,c)
{
	onFilterTypeSelected(c,FilterType[c][1]);
})








//////////////////////////////////////////
/////////////////Soft List Grid
//////////////////////////////////////////
	var grid_list = new Ext.grid.GridPanel({
        store: store,
        columns: [
            {id:'Assets_tb_id',header: "Workstation", width: 140, sortable: true, dataIndex: 'st_Workstation'},
            {header: "Model", width: 85, sortable: true,  dataIndex: 'st_Model'},
            {header: "OS", width: 125, sortable: true,  dataIndex: 'st_OS'},
            {header: "Service Tag", width: 85, sortable: true,  dataIndex: 'st_Service_Tag'},
			{header: "Asset State", width: 85, sortable: true,  dataIndex: 'st_Asset_State'},
			{header: "User", width: 95, sortable: true,  dataIndex: 'st_User'},
            {header: "Department", width: 105, sortable: true,  dataIndex: 'st_Department'}
        ],
		tbar: new Ext.Toolbar({
			items:[
				{
					text:"New",
					handler:createNewSoftware
				},
				{
					xtype:"tbspacer"
				},
				{
					text:"Delete",
					handler:deleteSoftware
				},
				{
					xtype:"tbspacer"
				},
				{
					text:"Change",
					handler:changeSoftware
				},
				{
					xtype:"tbspacer"
				},
				{
					xtype:"tbseparator"
				},
				{
					xtype:"tbspacer"
				},
				{
					xtype: 'tbtext',
					text: '<span style="font-weight:bold;">Filter :</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Viewing'
				},
				{
					xtype:"tbspacer"
				},
				filter_type_combo,
				{
					xtype:"tbspacer"
				},
				{
					xtype:"tbspacer"
				}
			]
		}),
		bbar: new Ext.PagingToolbar({
            pageSize: 25,
            store: store,
            displayInfo: true,
            displayMsg: 'Displaying topics {0} - {1} of {2}',
            emptyMsg: "No topics to display",
            items:[]
        }),
        stripeRows: true,
        autoExpandColumn: 'Assets_tb_id',
        height:350,
        width:Ext.get("assets_list_content").getWidth(),
		autoWidth : true, 
        title:'Assets List'
    });

	
	try
	{
		viewport.on("resize",function(){
			grid_list.setWidth(Ext.get("assets_list_content").getWidth());
		})
	}catch(e){}
    grid_list.render('assets_list_content');
    grid_list.getSelectionModel().selectFirstRow();
//////////////////////////////////////////
/////////////////End Assets List Grid
//////////////////////////////////////////


/////////////////////////////////////////
////////////////Add new Assets Window
/////////////////////////////////////////
/*Software Name
Version
Software Type
Software Category
Description*/

add_workstation_Form = new Ext.FormPanel({
	width:630,
	bodyBorder :false,
	border :false,
	url:add_assets_post_url,
	
	onSubmit: Ext.emptyFn,
	submit: function() 
	{
		this.getForm().getEl().dom.action = this.url;
		this.getForm().getEl().dom.submit();
	},
	items:
	{
		xtype:'tabpanel',
		activeTab: 0,
        defaults:{autoHeight:true, bodyStyle:'padding:10px'}, 
		items:
		[
			{
				title:'Personal Details',
				layout:'form',
				defaults: {width: 230},
				defaultType: 'textfield',
				items:
				[
					{
			            layout:'column',
						border :false,
						items:
						[{
						    columnWidth:.5,
            			    layout: 'form',
							border :false,
							items:
							[
								{
									xtype:'textfield',
									allowBlank:false,
									fieldLabel: 'Asset Name',
									name: 'add_product_form_asset',
									anchor:'100%'
								},{
									xtype:'textfield',
									allowBlank:false,
									fieldLabel: 'Asset Name',
									name: 'add_product_form_asset',
									anchor:'100%'
								}
							]
						},{
						    columnWidth:.5,
            			    layout: 'form',
							border :false,
							items:
							[
								{
									xtype:'textfield',
									allowBlank:false,
									fieldLabel: 'Asset Name',
									name: 'add_product_form_asset',
									anchor:'100%'
								},{
									xtype:'textfield',
									allowBlank:false,
									fieldLabel: 'Asset Name',
									name: 'add_product_form_asset',
									anchor:'100%'
								}
							]
						}]
					}
					/*{
						xtype:'textfield',
						allowBlank:false,
						fieldLabel: 'Software Name<span style="color:red;">*</span>',
						name: 'add_sw_sw_name',
						anchor:'100%'
					},{
								xtype:'combo',
								store:software_type_store,
								valueField:'returnValue',
								displayField:'textValue',
								mode:'local',
								blankText:'Software Type',
								editable:false,
								triggerAction:'all',
								fieldLabel: 'Software Type',
								name: 'add_sw_type',
								anchor:'70%'
					}*/
				]
			}
		]
	}
});
function sendAddRequest()
{
	add_software_Form.submit();
}
var add_new_window = new Ext.Window({
	title: 'Add New Workstation',
	width: 630,
	height:340,
	minWidth: 300,
	minHeight: 200,
	layout: 'fit',
	plain:true,
	buttonAlign:'center',
	items: add_workstation_Form,
	modal:true,
	buttons: [{
		text: 'Add',
		handler:function(){sendAddRequest();}
	},{
		text: 'Cancel',
		handler:function(){add_new_window.hide();}
	}]
})

add_new_window.on("beforeclose",function(){add_new_window.hide();return false;})

//add_software_Form.render(document.body);
/////////////////////////////////////////
////////////////End Add new Assets Window
/////////////////////////////////////////



